@page "/k8s/tpl/list"
@using FOPS.Abstract.K8S.Entity
@using FOPS.Abstract.K8S.Server
@inject IIocManager _iocManager;
@inject NavigationManager nav;

<div class="layui-card">
    <div class="layui-card-header" id="anchor-play-header">
        Yaml模板
        <div class="layui-right">
            <button class="layui-btn layui-btn-right" @onclick=GotoAdd><i class="am-icon-plus"></i> 添加Yaml模板</button>
        </div>
    </div>
    <div class="layui-card-body">
        <div class="layui-form layui-border-box layui-table-view" lay-filter="LAY-table-1" style=" ">
            <div class="layui-table-box">
                <div class="layui-table-header">
                    <table cellspacing="0" cellpadding="0" border="0" class="layui-table" lay-skin="auto" lay-size="sm">
                        <thead>
                        <tr>
                            <th data-field="ID">
                                <div class="layui-table-cell laytable-cell-14-0-0">
                                    <span>ID</span>
                                </div>
                            </th>
                            <th data-field="Type">
                                <div class="layui-table-cell laytable-cell-14-0-1">
                                    <span>k8s类型</span>
                                </div>
                            </th>
                            <th data-field="Title">
                                <div class="layui-table-cell laytable-cell-14-0-2">
                                    <span>模板名称</span>
                                </div>
                            </th>
                        </tr>
                        </thead>
                    </table>
                </div>
                <div class="layui-table-body layui-table-main">
                    <table cellspacing="0" cellpadding="0" border="0" class="layui-table" lay-skin="auto" lay-size="sm">
                        <tbody>
                        @for (var index = 0; index < _lst.Count; index++)
                        {
                            var info = _lst[index];
                            <tr data-index="@index">
                                <td>
                                    <div class="layui-table-cell laytable-cell-14-0-0"> @info.Id</div>
                                </td>
                                <td data-field="Type">
                                    <div class="layui-table-cell laytable-cell-14-0-1">
                                        @info.K8SKindType.ToString()
                                    </div>
                                </td>
                                <td data-field="Title">
                                    <div class="laytable-cell-14-0-2">
                                        <a href="/k8s/tpl/update/@info.Id">@info.Name</a>
                                    </div>
                                </td>
                            </tr>
                        }
                        </tbody>
                    </table>
                </div>
            </div>
            <PageSplit PageIndex="1" PageSize="@_pageSize" TotalCount="@_totalCount" PageUrl="/k8s/tpl/list/{index}"></PageSplit>
        </div>
    </div>
</div>
<style>
    .laytable-cell-14-0-0{ width: 80px; }
    .laytable-cell-14-0-1{ width: 150px; }
    .laytable-cell-14-0-2{ width: 500px; }
</style>

@code{

    private int _totalCount;
    private int _pageSize = 999;

    private List<YamlTplVO> _lst = new();
    private bool _isFirst;

    protected override async Task OnParametersSetAsync()
    {
        if (_isFirst) return;
        _isFirst = true;

        _lst = await _iocManager.Resolve<IYamlTplService>().ToListAsync()??new();
        _lst = _lst.OrderBy(o => o.K8SKindType).ToList();
        _totalCount = _lst.Count;
    }

    private void GotoAdd()
    {
        nav.NavigateTo("/k8s/tpl/add");
    }
}